﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Chuong4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btTao_Primes_Click(object sender, EventArgs e)
        {
            SoNguyenTo snt = new SoNguyenTo();
            BigInteger so = snt.Creat();
            txtCreate_Primes.Text = so.ToString();
        }

        private void btKiemTra_Primes_Click(object sender, EventArgs e)
        {
            BigInteger n = BigInteger.Parse(txtN_Primes.Text);
            SoNguyenTo snt = new SoNguyenTo();
            if (snt.isPrimes(n))
                MessageBox.Show("Là số nguyên tố");
            else MessageBox.Show("Không là số nguyên tố");
        }

        private void btRabinMiller_Primes_Click(object sender, EventArgs e)
        {
            BigInteger n = BigInteger.Parse(txtN_Primes.Text);
            if (n > 1)
            {
                SoNguyenTo snt = new SoNguyenTo();
                if (snt.Rabin_Miller(n, 100))
                    MessageBox.Show("Là số nguyên tố");
                else MessageBox.Show("Không là số nguyên tố");
            }
            else MessageBox.Show("Không là số nguyên tố");
        }

        private void btMonteCarlo_Factor_Click(object sender, EventArgs e)
        {
            PhanTich pt = new PhanTich(BigInteger.Parse(txtN_Factor.Text));
            pt.MonteCarlo(100);
            txtX.Text = pt.X.ToString();
            txtY.Text = pt.Y.ToString();
        }

        private void btFermat_Factor_Click(object sender, EventArgs e)
        {
            PhanTich pt = new PhanTich(BigInteger.Parse(txtN_Factor.Text));
            pt.Fermat();
            txtX.Text = pt.X.ToString();
            txtY.Text = pt.Y.ToString();
        }

        private void btRho_Factor_Click(object sender, EventArgs e)
        {
            PhanTich pt = new PhanTich(BigInteger.Parse(txtN_Factor.Text));
            pt.Rho();
            txtX.Text = pt.X.ToString();
            txtY.Text = pt.Y.ToString();
        }

        private void btVetCan_Logarithm_Click(object sender, EventArgs e)
        {
            Logarit lg = new Logarit(BigInteger.Parse(txtA_Logarithm.Text), BigInteger.Parse(txtN_Logarithm.Text), BigInteger.Parse(txtB_Logarithm.Text));
            lg.VetCan();
            txtKQ_Logarithm.Text = lg.X.ToString();
        }

        private void btnBabyGiant_Click(object sender, EventArgs e)
        {
            Logarit lg = new Logarit(BigInteger.Parse(txtA_Logarithm.Text), BigInteger.Parse(txtN_Logarithm.Text), BigInteger.Parse(txtB_Logarithm.Text));
            lg.BaybyGiant();
            txtKQ_Logarithm.Text = lg.X.ToString();
        }

        
    }
}
